package ca.cbc.giscommon.dao;

import java.util.Formatter;
import java.util.List;

import org.hibernate.criterion.Restrictions;

import com.vividsolutions.jts.geom.Geometry;

import ca.cbc.giscommon.entity.Zone;
import ca.cbc.giscommon.util.GeometryUtil;

public class ZoneDAO extends EntityHome<Zone>{

	@Override
	public String getFullClassName() {
		return Zone.class.getCanonicalName();
	}
	
    @SuppressWarnings("unchecked")
	public List<Zone> getZones(Geometry geo) {
    	String query = new Formatter().format("ST_Intersects(this_.the_geom, ST_GeomFromText('%s', %d))", geo.toString(), GeometryUtil.instance.getSRID()).toString();
    	List<Zone> zones = getCurrentSession().createCriteria(Zone.class).add(Restrictions.sqlRestriction(query)).list();
    	return zones;
    }
}
